package com.zeei.bfs.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zeei.bfs.dao.SessionDao;
import com.zeei.bfs.dao.UserDao;
import com.zeei.bfs.service.SessionService;
import com.zeei.common.vo.SessionVO;
import com.zeei.common.vo.UserVO;

@Service("sessionService")
public class SessionServiceImpl extends BasicServiceImpl implements SessionService {
	@Autowired
	private SessionDao sessionDao;

	@Autowired
	private UserDao userDao;

	@Override
	public void updateExpiringDate(String sessionId) {
		sessionDao.updateExpiringDate(sessionId);
	}

	@Override
	public void deleteSessionByUserId(Integer userId) {
		sessionDao.deleteSessionByUserId(userId);
	}

	@Override
	public UserVO querySessionById(String sessionId) {
		List<SessionVO> list = sessionDao.querySessionById(sessionId);
		if (list == null || list.isEmpty()) {
			return new UserVO();
		} else {
			UserVO user = new UserVO();
			user.setUserid(list.get(0).getUserid());
			List<UserVO> userlist = userDao.queryUserByUserId(list.get(0).getUserid());
			return userlist.get(0);
		}

	}

	@Override
	public void saveUserSession(HashMap<String, Object> hashMap) {
		sessionDao.saveUserSession(hashMap);
	}

	@Override
	public void deleteSessionBySessionId(String sessionId) {
		sessionDao.deleteSessionBySessionId(sessionId);
	}
}
